/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * NuGat-API named Chameleon developed by Simon De Baets to Verimag.
 *
 */


package chameleon.model.NuGatStructure.utils;

import chameleon.gameSolver.NuGat.NuGatInterface;
import chameleon.model.NuGatStructure.NuGatStructure;
import com.sun.jna.Pointer;

/**
 *
 * This class is a wrapper to the C struct NodeList
 *
 * @author simon
 */
public class NodeList extends NuGatStructure {


    public NodeList(Pointer nodeList, NuGatInterface nugat){
        super(nodeList,nugat);
    }

    /**
     * This function print all the nodes contains in the list in the file given
     * on parameter.
     * @param file
     */
    public void printNodes( String fileName){
        nugat_.NodeList_print_nodes(this.ptr(), nugat_.CmdOpenFile(fileName));
    }

    /**
     * Convert a NodeList to a node_ptr
     * @return node_ptr
     */
    public Node NodeListToNode(){
        return new Node(nugat_.NodeList_to_node_ptr(this.ptr()),nugat_);
    }

    /**
     * This function return the first iterator for the actual NodeList.
     * @param NodeList_ptr
     * @return ListIter_ptr
     */
    public Pointer getFirstIter(){
        return nugat_.NodeList_get_first_iter(this.ptr());
    }

    /**
     * Return true if we are on the end of the list.
     * @param ListIter_ptr
     * @return
     */
    public boolean ListIterIsEnd(Pointer ListIter_ptr){
        return (ListIter_ptr == Pointer.NULL);
    }

    /**
     * This function return the next iterator.
     * @param ListIter_ptr
     * @return ListIter_ptr
     */
    public Pointer ListIterGetNext(Pointer ListIter_ptr ){
        return nugat_.ListIter_get_next(ListIter_ptr);
    }

    /**
     * Return the element at the given position
     *
     * @param ListIter_ptr
     * @return
     */
    public Node getElemAt( Pointer ListIter_ptr){
        return new Node (nugat_.NodeList_get_elem_at(this.ptr(), ListIter_ptr),
                nugat_);
    }

    /**Function********************************************************************

      Synopsis           [Append all the elements in src to self]

      Description        [Cost is linear in the size of src]

      SideEffects        [Content of self will change is src is not empty]

      SeeAlso            []

    ******************************************************************************/
    
    public void concat(NodeList src){
        nugat_.NodeList_concat(this.ptr(), src.ptr());
    }
}
